package cn.edu.scut.hsrc.input;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

import cn.edu.scut.hsrc.bean.Doc;

/**
 * 这个类的主要作用就是通过读取文件，获取聚类的源数据
 * @author feiyu
 *
 */
public class FileInputAdapter implements InputAdapter {
	
	private File file;
	
	/**
	 * 构造函数
	 * @param file
	 */
	public FileInputAdapter(File file) {
		// TODO Auto-generated constructor stub
		this.file = file;
	}
	
	public List<Doc> initData(int start, int count) {
		// TODO Auto-generated method stub
		try {
			BufferedReader br = new BufferedReader(new FileReader(file));
			String title;
			String summary;
			// 整个连贯的查询
			List<Doc> dataList = new ArrayList<Doc>();
			int i = 0;
			int end = start + count;
			while (br.ready() && i<end) {
				title = br.readLine();
				summary = br.readLine();
				if(i>=start)
					dataList.add(new Doc(i-start,title, summary));
				i++;
			}
			return dataList;
		} catch (Exception ex) {
			ex.printStackTrace();
			return null;
		}
	}
	
	public static void main(String[] args) {
		File file = new File("F://clustering//ourresult//百慕大失踪");
		InputAdapter input = new FileInputAdapter(file);
		List<Doc> docs = input.initData(2, 10);
		for (Doc doc : docs) {
			System.out.println("文档编号: "+doc.getIndex());
			System.out.println("Title: "+doc.getTitle());
			System.out.println("Summary: "+doc.getSummary());
		}
	}
}
